a=10
b=false
print( a and b )
print( a or b )

function function_01( a,b )
    -- body
    local x = nil;
    x= string.format("This function_01 a=%d",a)
    print(string.format("This function_01 a=%d",a) );
    print( x );
    return a+b
end

function function_02( a,b,... )
    -- body
    print("%d",a )
end

function print_lua_table (lua_table, indent)
    indent = indent or 0
    for k, v in pairs(lua_table) do
        if type(k) == "string" then
            k = string.format("%q", k)
        end
        local szSuffix = ""
        if type(v) == "table" then
            szSuffix = "{"
        end
        local szPrefix = string.rep("    ", indent)
        formatting = szPrefix.."["..k.."]".." = "..szSuffix
        if type(v) == "table" then
            print(formatting)
            print_lua_table(v, indent + 1)
            print(szPrefix.."},")
        else
            local szValue = ""
            if type(v) == "string" then
                szValue = string.format("%q", v)
            else
                szValue = tostring(v)
            end
            print(formatting..szValue..",")
        end
    end
end
function function_3( n )
    -- body
    if n==0 then
        return 1;
    else
        return n*function_3(n-1)
    end
end

local x = {a = 20,20,60,{a = {a = 1,2323},2323}}
print_lua_table(x)

for i=0,10 do
    -- print 连接内容
    print("now i:"..i.." hello world");
end
page = 
[[
<HTML>
<HEAD>
<TITLE>An HTML Page</TITLE>
</HEAD>
<BODY>
Lua
</BODY>
</HTML>
]]

print( function_01(10.10,20) )
print( function_02(1,2,3) )
print( string.format("type of 4 is:%s",type(4)) )
print( string.format("type of x is:%s",type(x)) )
print( "function_3="..function_3(0) )
print( "plese enter a number:" )
-- a = io.read("*number")
-- print("enter number ="..a)
print( "function_3="..function_3(a) )
print(page)
a=1;b=2;c=3;
print( (a and b) or c)
a=true;b=false
print( (a and b) or c)
polyline = 
{
    color="blue", thickness=2, npoints=4;
    {x=0, y=0},
    {x=-10, y=0},
    {x=-10, y=1},
    {x=0, y=1}
}
print( polyline["color"] )
print( polyline.color )
print( "x=" .. polyline[1].x .. " y=" .. polyline[1].y )
print( "x=" .. polyline[2].x .. " y=" .. polyline[2].y )
print( "x=" .. polyline[3].x .. " y=" .. polyline[3].y )
print( "x=" .. polyline[4].x .. " y=" .. polyline[4].y )
x=2
do 
    --此处的x是局部变量 
    local x=0;
    while true do
        x = x+1
        print("x=" .. x )
        if x>10 then 
            break;
        end 
    end 
end     
print("x=".. x)

do 
local y = 0;
    repeat 
        print( "y=".. y)
        y= y+1
    until(y>5)
end  
days = {"Suanday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}


--[[
    i是数组索引值，v是对应索引的数组元素值。
    ipairs是Lua提供的一个迭代器函数，用来迭代数组。
]] 
for i,v in ipairs(days) do 
    print( "i=".. i .." ".. v ) 
end 

function function_arg( ... )
    arg = {...}
    for i,v in ipairs(arg) do
        print("data in arg : ".. i .." value: ".. v)
    end
end


function_arg(1,2,"hallo world")
network = 
{
    {name = "grauna", IP = "210.26.30.34"},
    {name = "arraial",  IP = "210.26.30.23"},
    {name = "lua",  IP = "210.26.23.12"},
    {name = "derain", IP = "210.26.23.20"},
}
-- 排序 ，从大到小
print("name 从大到小排序")
table.sort( network,function (a,b) return (a.name > b.name) end )
print_lua_table( network )
-- 排序 ，从小到大
print("name 从小到大排序")
table.sort( network,function (a,b) return (a.name < b.name) end )
print_lua_table( network )
print("IP 从大到小排序")
table.sort( network,function (a,b) return (a.IP > b.IP) end )
print_lua_table( network )
-- a1=10
-- print("hello world =",a1 )
do
    function list_iter (t)
        local i = 0
        local n = 3--table.getn(t)
        print( "1.now i=",i)
        return function ()
            print( "2.now i=",i)
            i = i + 1
            if i <= n then return t[i] end
        end
    end

    t = {10, 20, 30}
    for element in list_iter(t) do
    print(element)
    end
end 
print( "lua demo End : ".. os.date() )

